//
//  HWTrialSwitchCell.m
//  HuaWan
//
//  Created by HuaWan  on 2023.
//  Copyright © 2023 HuaWan . All rights reserved.
//

#import "HWTrialSwitchCell.h"

@implementation HWTrialSwitchCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    //打开背景色
    _mySwitch.onTintColor = UIColorFromHex(0x68E8B3);
    //关闭背景色
    _mySwitch.tintColor = UIColorFromHex(0x1F1944);
    //圆球
    _mySwitch.thumbTintColor = UIColorFromHex(0xFFFFFF);
    
}

- (void)setData:(id)data delegate:(id)delegate {

    _delegate = delegate;
        
    if ([data isKindOfClass:[NSDictionary class]]) {
        if ([data[@"data"] isKindOfClass:[HWTrialSwitchCellModel class]]) {
            HWTrialSwitchCellModel *model = data[@"data"];
            _model = model;
            _titleLabel.text = model.title;

            _mySwitch.on = model.isOn;
        }
    }
}

- (IBAction)mySwitchValueChanged:(UISwitch *)sender {
    
    if (_delegate && [_delegate respondsToSelector:@selector(trialSwitchCell:isOn:)]) {
        [_delegate trialSwitchCell:self isOn:sender.on];
    }
}

@end


#pragma mark - Model

@implementation HWTrialSwitchCellModel

+ (HWTrialSwitchCellModel *)ittemModelWithTitle:(NSString *)title isOn:(BOOL)isOn {
    HWTrialSwitchCellModel *model = [HWTrialSwitchCellModel new];
    model.title = kSafeString(title);
    model.isOn = isOn;
    return model;
}

@end
